gdk/gl: Allow autodetection for GL/GLES
authorEmmanuele Bassi <ebassi@gnome.org>
Wed, 19 Oct 2016 12:43:17 +0000 (13:43 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 21 Oct 2016 15:39:24 +0000 (11:39 -0400)
If the GdkGLContext was not explicitly instructed to use or not GLES, we
can detect whether the underlying API is going to be desktop GL or GLES.

https://bugzilla.gnome.org/show_bug.cgi?id=773180

gdk/gdkglcontext.c
gdk/gdkglcontext.h

index 216a19a4cb1a63deb1a8e1a34db67b24a188e5b0..248ce1148d38fade6579607c5e1bbf31dde5b0ba 100644 (file)
@@ -105,7 +105,8 @@ typedef struct {
   guint debug_enabled : 1;
   guint forward_compatible : 1;
   guint is_legacy : 1;
-  guint use_es : 1;
+
+  int use_es;
 
   GdkGLContextPaintData *paint_data;
 } GdkGLContextPrivate;
@@ -362,6 +363,9 @@ gdk_gl_context_class_init (GdkGLContextClass *klass)
 static void
 gdk_gl_context_init (GdkGLContext *self)
 {
+  GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (self);
+
+  priv->use_es = -1;
 }
 
 /*< private >
@@ -683,13 +687,18 @@ gdk_gl_context_set_is_legacy (GdkGLContext *context,
 /**
  * gdk_gl_context_set_use_es:
  * @context: a #GdkGLContext:
- * @use_es: whether the context should use OpenGL ES instead of OpenGL
+ * @use_es: whether the context should use OpenGL ES instead of OpenGL,
+ *   or -1 to allow auto-detection
  *
  * Requests that GDK create a OpenGL ES context instead of an OpenGL one,
  * if the platform and windowing system allows it.
  *
  * The @context must not have been realized.
  *
+ * By default, GDK will attempt to automatically detect whether the
+ * underlying GL implementation is OpenGL or OpenGL ES once the @context
+ * is realized.
+ *
  * You should check the return value of gdk_gl_context_get_use_es() after
  * calling gdk_gl_context_realize() to decide whether to use the OpenGL or
  * OpenGL ES API, extensions, or shaders.
@@ -698,14 +707,15 @@ gdk_gl_context_set_is_legacy (GdkGLContext *context,
  */
 void
 gdk_gl_context_set_use_es (GdkGLContext *context,
-                           gboolean      use_es)
+                           int           use_es)
 {
   GdkGLContextPrivate *priv = gdk_gl_context_get_instance_private (context);
 
   g_return_if_fail (GDK_IS_GL_CONTEXT (context));
   g_return_if_fail (!priv->realized);
 
-  priv->use_es = !!use_es;
+  if (priv->use_es != use_es)
+    priv->use_es = use_es;
 }
 
 /**
@@ -725,7 +735,10 @@ gdk_gl_context_get_use_es (GdkGLContext *context)
 
   g_return_val_if_fail (GDK_IS_GL_CONTEXT (context), FALSE);
 
-  return priv->use_es;
+  if (!priv->realized)
+    return FALSE;
+
+  return priv->use_es > 0;
 }
 
 /**
@@ -771,6 +784,9 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
 
   priv->gl_version = epoxy_gl_version ();
 
+  if (priv->use_es < 0)
+    priv->use_es = !epoxy_is_desktop_gl ();
+
   if (priv->use_es)
     {
       has_npot = priv->gl_version >= 20;
index 44633a7c8a8f1d199f351c91ced1a037a26ffb4a..eb380c2f2546634c8d1f37f97d52651b3e0829b6 100644 (file)
@@ -75,7 +75,7 @@ GDK_AVAILABLE_IN_3_16
 gboolean                gdk_gl_context_get_forward_compatible   (GdkGLContext  *context);
 GDK_AVAILABLE_IN_3_22
 void                    gdk_gl_context_set_use_es               (GdkGLContext  *context,
-                                                                 gboolean       use_es);
+                                                                 int            use_es);
 GDK_AVAILABLE_IN_3_22
 gboolean                gdk_gl_context_get_use_es               (GdkGLContext  *context);